package com.car.slave.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.car.slave.im.IMClient;
import com.imchezhil.R;

public class LoginActivity extends Activity {
	
	private EditText username;
	private EditText password;
	private Button login;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		
		initView();
		initViewData();
		initViewListener();
	}

	private void initView() {
		username = (EditText) findViewById(R.id.username);
		password = (EditText) findViewById(R.id.password);
		login = (Button) findViewById(R.id.login);
	}
	
	private void initViewData() {
		
	}
	
	private void initViewListener() {
		login.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if (TextUtils.isEmpty(username.getText().toString())) {
					Toast.makeText(LoginActivity.this, "请输入用户名", Toast.LENGTH_SHORT).show();
					return;
				}
				if (TextUtils.isEmpty(password.getText().toString())) {
					Toast.makeText(LoginActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
					return;
				}
				IMClient.shareInstance().login(LoginActivity.this, username.getText().toString() + ":" + password.getText().toString(),
						"token", "clientId", "", "","","","");

				Intent intent = new Intent(LoginActivity.this, MainActivity.class);
				startActivity(intent);
				finish();
			}
		});
	}
}
